<!--  -->
<template>
  <div>
    <el-dialog title="编辑宿舍信息" :visible.sync="diaShow" width="30%" @close="close">
      <el-form :model="dormItem" ref="form" label-width="80px">
        <el-form-item label="宿舍名称">
          <el-input v-model="dormItem.name"></el-input>
        </el-form-item>
        <el-form-item label="宿舍地址">
          <el-input v-model="dormItem.position"></el-input>
        </el-form-item>
        <el-form-item label="宿舍描述">
          <el-input v-model="dormItem.bak" type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="宿舍类型">
          <el-select v-model="dormItem.type" placeholder>
            <el-option label="男生宿舍" :value="0"></el-option>
            <el-option label="女生宿舍" :value="1"></el-option>
            <el-option label="未定" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-date-picker
            type="date"
            value-format="yyyy-MM-dd"
            v-model="dormItem.startTime"
            placeholder="选择日期时间"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker
            type="date"
            value-format="yyyy-MM-dd"
            v-model="dormItem.endTime"
            placeholder="选择日期时间"
          ></el-date-picker>
        </el-form-item>
      </el-form>
      <img src="http://bufanui.com/pages/front/img/en_8.jpg" style="width:100%" alt="">
      <span slot="footer">
        <el-button @click="diaShow= false">取 消</el-button>
        <el-button type="primary" @click="addDorm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  dormDesc,
  addDormList,
  updateDormList,
} from "@/api/students/dormList";
export default {
  name: "dormDetails",
  data() {
    return {
      diaShow: false,
      dormItem: {},
    };
  },
  methods: {
    openAdd() {
      this.dormItem = {};
      this.open();
    },
    openDetauls(id) {
      console.log(id);
      this.open();
      dormDesc({ id: id }).then((res) => {
        console.log(res);
        this.dormItem = res.data;
      });
    },
    open() {
      this.diaShow = true;
    },
    close() {
      this.diaShow = false;
    },
    addDorm() {
      var api = null;
      if (this.dormItem.id) {
        api = updateDormList;
      } else {
        api = addDormList;
      }
      var obj = {
        xyDormInfo: {
          ...this.dormItem,
        },
      };
      api(obj).then((res) => {
        if (res.code == true) {
          this.$emit("toInit");
        }
      });
      this.close();
    },
  },
};
</script>

<style  lang='scss' scoped >
</style>
